<?php
	class dathangdb
	{
		public function Add($MaNguoiDung, $DiaChiGiaoHang, $DienThoai)
		{
			$sql = "INSERT INTO `tbl_dathang`(`MaNguoiDung`, `DiaChiGiaoHang`, `DienThoai`, `NgayDatHang`, `TinhTrang`)
				VALUES($MaNguoiDung, '$DiaChiGiaoHang', '$DienThoai', now(), 0)";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaDatHang)
		{
			$sql = "DELETE FROM `tbl_dathang` WHERE MaDatHang = $MaDatHang";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Update($MaDatHang, $DiaChiGiaoHang, $DienThoai)
		{
			$sql = "UPDATE `tbl_nhomhang` SET DiaChiGiaoHang='$DiaChiGiaoHang', DienThoai = '$DienThoai' WHERE MaDatHang = $MaDatHang"; 
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	
		public function GetList($MaDatHang, $MaNguoiDung, $DiaChiGiaoHang, $DienThoai)
		{
			$sql = " SELECT * FROM `tbl_dathang`, `tbl_nguoidung` WHERE tbl_dathang.MaNguoiDung = tbl_nguoidung.MaNguoiDung ";
			if($MaDatHang!="")
				$sql .= " AND tbl_dathang.MaDatHang = $MaDatHang ";
			if($MaNguoiDung!="")
				$sql .= " AND tbl_dathang.MaNguoiDung = $MaNguoiDung ";
			if($DiaChiGiaoHang!="")
				$sql .= " AND tbl_dathang.DiaChiGiaoHang LIKE '%$DiaChiGiaoHang%' ";
			if($DienThoai!="")
				$sql .= " AND DienThoai = '$DienThoai' ";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		public function Find($MaNhomHang, $TenNhomHang)
		{
			$sql = "SELECT * FROM `tbl_dathang`, `tbl_nguoidung` WHERE tbl_dathang.MaNguoiDung = tbl_nguoidung.MaNguoiDung ";
			if($MaNhomHang!="" || $TenNhomHang!="")
				$sql = " SELECT * FROM `tbl_dathang`, `tbl_nguoidung` WHERE tbl_dathang.MaNguoiDung = tbl_nguoidung.MaNguoiDung OR tbl_dathang.MaDatHang = $MaDatHang OR  tbl_dathang.MaNguoiDung = $MaNguoiDung OR tbl_dathang.DiaChiGiaoHang LIKE '%$DiaChiGiaoHang%' OR tbl_dathang.DienThoai = '$DienThoai'";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
	}
?>